how to search for a file under a directory

Hello,

I want to search for a file under the directory.
I will get the directory info by getenv(systemroot).
under that i have to search for one file.
because the file will be under different locations under different machines.
kindly help me out.

Thank you!

Regards,
Shruthi
Bosch - Mon Nov 07 02:00:02 EST 2011

Re: how to search for a file under a directory
SystemAdmin - Mon Nov 07 06:26:45 EST 2011

Maybe the "fileExists_" function from lib\dxl\utils\fileops.dxl (under your DOORS installation directory) could be useful.

  • Pekka Mäkinen - http://www.softqa.eu/

Re: how to search for a file under a directory
OurGuest - Mon Nov 07 07:12:30 EST 2011

One approach is to issue a dos DIR command then parse the results to find the path.

Re: how to search for a file under a directory
llandale - Mon Nov 07 14:32:02 EST 2011

Here is some old cob-web code, maybe you can make enough sense out of it.

//********************
void    SearchDir(string NameDir, bool Recurse, Buffer &Results)
{             // display the folders and files in the directory
                // Optionally Recurs through subfolders
                // This function is RECURSION enabled
        string  NameFile
        string  NameFull
        Stat    stat
 
        set (dbeStatus, "... '" NameDir "'")
        g_NumFolders++
        Results += "\n..." NameDir[g_OriginLen:]"\n"
 
                // *** [1] Print the info of all SubFolders
        for NameFile in directory NameDir do
        {  if (NameFile[0:0] == ".")        // skip the "." and ".." file names.  No other name may begin with '.'
              continue
           if (NameFile == NameDir)     // Don't recall why, but skip a file with exact name as Directory
              continue
           NameFull     = NameDir "\\" NameFile
           stat = create(NameFull)
//    print "considering >" NameFull "<\n"
           if (!null stat and directory(stat))
              DisplayInfo(stat, true, NameDir, NameFile, Results)
           if (!null stat) delete(stat)
        }
                // *** [2] Print the info of all Files
        for NameFile in directory NameDir do
        {  if (NameFile[0:0] == ".")
              continue
           if (NameFile == NameDir)
              continue
           g_NumFiles++
           NameFull     = NameDir "\\" NameFile
           stat = create(NameFull)
           if (!null stat and (regular(stat) or symbolic(stat)))
               DisplayInfo(stat, false, NameDir, NameFile, Results)
           if (!null stat) delete(stat)
        }
 
                // *** [3] Recurs through SubFolders
        if (Recurse)
        {  for NameFile in directory NameDir do
           {  if (NameFile[0:0] == ".")
                continue
              NameFull = NameDir "\\" NameFile
              stat      = create(NameFull)
              if (!null stat and directory(stat))
              {  // print "*** NOT Doing >" NameFull "<\n"
                 SearchDir(NameFull, Recurse, Results)  // ** RECURSION **
              }
              if (!null stat) delete(stat)
           }
        }
}    // end SearchDir()


I'd be particularly interested in this line:

if (NameFile == NameDir) // Don't recall why, but skip a file with exact name as Directory
continue

as I don't recall what that was all about.

 

  • Louie

 

Re: how to search for a file under a directory
Bosch - Tue Nov 08 00:24:33 EST 2011

llandale - Mon Nov 07 14:32:02 EST 2011

Here is some old cob-web code, maybe you can make enough sense out of it.

//********************
void    SearchDir(string NameDir, bool Recurse, Buffer &Results)
{             // display the folders and files in the directory
                // Optionally Recurs through subfolders
                // This function is RECURSION enabled
        string  NameFile
        string  NameFull
        Stat    stat
 
        set (dbeStatus, "... '" NameDir "'")
        g_NumFolders++
        Results += "\n..." NameDir[g_OriginLen:]"\n"
 
                // *** [1] Print the info of all SubFolders
        for NameFile in directory NameDir do
        {  if (NameFile[0:0] == ".")        // skip the "." and ".." file names.  No other name may begin with '.'
              continue
           if (NameFile == NameDir)     // Don't recall why, but skip a file with exact name as Directory
              continue
           NameFull     = NameDir "\\" NameFile
           stat = create(NameFull)
//    print "considering >" NameFull "<\n"
           if (!null stat and directory(stat))
              DisplayInfo(stat, true, NameDir, NameFile, Results)
           if (!null stat) delete(stat)
        }
                // *** [2] Print the info of all Files
        for NameFile in directory NameDir do
        {  if (NameFile[0:0] == ".")
              continue
           if (NameFile == NameDir)
              continue
           g_NumFiles++
           NameFull     = NameDir "\\" NameFile
           stat = create(NameFull)
           if (!null stat and (regular(stat) or symbolic(stat)))
               DisplayInfo(stat, false, NameDir, NameFile, Results)
           if (!null stat) delete(stat)
        }
 
                // *** [3] Recurs through SubFolders
        if (Recurse)
        {  for NameFile in directory NameDir do
           {  if (NameFile[0:0] == ".")
                continue
              NameFull = NameDir "\\" NameFile
              stat      = create(NameFull)
              if (!null stat and directory(stat))
              {  // print "*** NOT Doing >" NameFull "<\n"
                 SearchDir(NameFull, Recurse, Results)  // ** RECURSION **
              }
              if (!null stat) delete(stat)
           }
        }
}    // end SearchDir()


I'd be particularly interested in this line:

if (NameFile == NameDir) // Don't recall why, but skip a file with exact name as Directory
continue

as I don't recall what that was all about.

 

  • Louie

 

Thank you so much.